package com.shuang.controller;

import com.shuang.pojo.Emp;
import com.shuang.pojo.LoginInfo;
import com.shuang.pojo.Result;
import com.shuang.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/*登录controller、*/
@RestController
@Slf4j
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("员工登录：{}", emp);

        LoginInfo loginInfo = empService.login(emp);

        //根据相应回来的结果判断登录是否成功
        if (loginInfo != null){
            return Result.success(loginInfo);
        }
        return Result.error("用户名或密码错误，请重新输入~");
    }
}
